<?php
namespace app\wxapp\controller;
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Vod\Vod;
use app\common\entity\Result;
use app\Request;
use app\wxapp\service\TopicService;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/10/20 0020
 * Time: 9:11
 */
class Topic extends Base{

    private $regionId = 'cn-shanghai';

    public function getTopic(Request $request){
        $id = $request->param('id');
        $service = new TopicService();
        $data = $service->getOne($id);
        return Result::success($data);
    }


    public function getPlayInfo(Request $request){
        $videoId = $request->param('videoId');
        $accessKeyId = env('aliyun.ali_access_key_id');
        $accessKeySecret = env('aliyun.ali_access_key_secret');
        AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)
            ->regionId($this->regionId)
            ->connectTimeout(1)
            ->timeout(3)
            ->asDefaultClient();

        $result = Vod::v20170321()->getPlayInfo()->withVideoId($videoId)
            ->format("JSON")
            ->request();

        return Result::success([
                'VideoBase'=>$result['VideoBase'],
                'PlayInfoList'=>$result['PlayInfoList'],
            ]
        );
    }

}